<?php

require_once('db.php');
connect_db('junyi', 'admin123', 'bookmark');
$out = array();

$username = mysql_real_escape_string($_POST["username"]);
$password = md5(mysql_real_escape_string($_POST["password"]));
$rem = $_POST["rem"];

if (login($username, $password)) {
  $out["info"] = "ok";
  $timeout = date("Y-m-d H:i:s");
  if ($rem == 1) {
    $timeout = strtotime($timeout . " +30 day");
  } else {
    $timeout = strtotime($timeout . " +1 day");
  }
  $timeout = date("Y-m-d H:i:s", $timeout);

  $session = create_session($username, $timeout);
  $out["session"] = $session;

} else {
  $out["info"] = "fail";
}


header("Content-type: application/json");
echo json_encode($out);

?>